package org.song.videoplayer.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

import org.song.videoplayer.HandleTouchEvent;
import org.song.videoplayer.QSVideoView;

/**
 * @Description: FinVideoViewControl
 * @Author: yiw89
 * @CreateDate: 2025/9/1 10:22
 * @Version: 1.0
 */
public abstract class FinVideoViewControl extends QSVideoView implements HandleTouchEvent.GestureEvent {

    /**
     * 交互控制UI容器
     */
    protected ViewGroup controlContainer;
    private HandleTouchEvent handleTouchEvent;


    public FinVideoViewControl(Context context) {
        super(context);
    }

    public FinVideoViewControl(Context context, AttributeSet attrs) {
        super(context, attrs,0);
    }

    public FinVideoViewControl(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    protected void initView(Context context) {
        handleTouchEvent = new HandleTouchEvent(this);

        controlContainer = (ViewGroup) View.inflate(context, getLayoutId(), null);
        videoView.addView(controlContainer, new LayoutParams(-1, -1));

        //手势事件监听
        videoView.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return handleTouchEvent.handleEvent(v, event);
            }
        });

    }

    /**
     * =========================================
     * -------子类需要实现的重要的方法------------
     * ========================================
     */
    protected abstract int getLayoutId();


    @Override
    public void onGestureBegin(int type) {

    }

    @Override
    public void onGestureChange(int type, float level) {

    }

    @Override
    public void onGestureEnd(int type, float level) {

    }
}
